// 练习3：使用帮助函数_average 重构averageDollarValue，使用函数组合的方式实现

const fp = require('lodash/fp')
const cars = require('./cars.json')

let _average = function (xs) {
  return fp.reduce(fp.add, 0, xs) / xs.length
}


// let averageDollarValue = function (cars) {
//   let dollar_value = fp.map(function (car) {
//     return car.dollar_value
//   }, cars)
//   console.log(dollar_value)
//   return _average(dollar_value)
// }


let averageDollarValue = fp.flowRight(_average,fp.map(fp.prop('dollar_value')))
console.log(averageDollarValue(cars))
